import api from './index'
import { service, apiBaseUrl } from '@/utils/request'
import axios from 'axios'
/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return service({
    url: '/sys/login',
    method: 'post',
    data: parameter
  })
}

export function phoneLogin(parameter) {
  return service({
    url: '/sys/phoneLogin',
    method: 'post',
    data: parameter
  })
}

export function easywork(code) {
  return service({
    url: `/single/jx/singleLogin?code=${code}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export function getSmsCaptcha(parameter) {
  return service({
    url: api.SendSms,
    method: 'post',
    data: parameter
  })
}

// export function getInfo() {
//   return service({
//     url: '/api/user/info',
//     method: 'get',
//     headers: {
//       'Content-Type': 'application/json;charset=UTF-8'
//     }
//   })
// }

export function logout(logoutToken) {
  // return service({
  //   url: '/jksaas-mgt/mgt/sys/logout',
  //   method: 'post',
  //   headers: {
  //     'Content-Type': 'application/json;charset=UTF-8',
  //     'X-Access-Token': logoutToken
  //   }
  // })
  return axios({
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'X-Access-Token': logoutToken
    },
    url: apiBaseUrl + '/jksaas-mgt/mgt/sys/logout',
  })
}

export function queryPermissionsByUser(token, type = '') {
  return axios({
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'X-Access-Token': token
    },
    url: apiBaseUrl + `/jksaas-mgt/mgt/newSys/permission/getUserPermissionByToken?menuFlag=2&antelopeFlag=${type}`,
  })
}
export function getComboEffectiveDate(token) {
  return axios({
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'X-Access-Token': token
    },
    url: apiBaseUrl + '/jksaas-mgt/mgt/newSys/permission/getComboEffectiveDate',
  })
}
export function getRoute(token, url, method = 'get') {
  return axios({
    method: method,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'X-Access-Token': token
    },
    url: apiBaseUrl + url
  })
}

/**
 * 第三方登录
 * @param token
 * @param thirdType
 * @returns {*}
 */
export function thirdLogin(token, thirdType) {
  return service({
    url: `/sys/thirdLogin/getLoginUser/${token}/${thirdType}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * 强退其他账号
 * @param token
 * @returns {*}
 */
export function forceLogout(parameter) {
  return service({
    url: '/sys/online/forceLogout',
    method: 'post',
    data: parameter
  })
}